<template>
	<view class="login">
		<button v-if="!isLogin && canIUseAuthButton" hover-class="none" class="login-button"
			@getphonenumber="getPhoneNumber" open-type="getPhoneNumber"></button>
		<slot></slot>
	</view>
</template>

<script>
	import {
		fetchGetPhone
	} from '@/services/user.js';
	import Config from '@/config/index.js';
	import store from '@/store/index.js'
	import {
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {
				canIUseAuthButton: true
			};
		},
		computed: {
			isLogin() {
				return store.state.user.isLogin
			} 
		},
		
		create() {
			console.log(store.state)
			// #ifdef MP-ALIPAY
			this.canIUseAuthButton = my.canIUse('button.open-type.getAuthorize');
			// #endif
		},
		methods: {
			async getPhoneNumber({
				detail
			}) {
				const resp = await fetchGetPhone({
					code: detail.code
				});
				this.$store.commit('setLoginState', true)
				uni.showToast({
					title: '登录成功',
					icon: 'none'
				})
				this.$emit('loginSucess');

			}
		}
	};
</script>

<style lang="scss">
	.login {
		position: relative;
	}

	.login-button {
		position: absolute;
		width: 100%;
		height: 100%;
		background: transparent;
		z-index: 1000;
	}
</style>
